'use strict';

module.exports = (option, app) => {
    return async (ctx, next) => {
        let appId = "";
        let method = ctx.request.method;
        if (method === "GET") {
            appId = ctx.request.query.appId;
        } else if (method === "POST") {
            appId = ctx.request.body.appId;
        }
        if (!appId) {
            ctx.body = `appId---参数错误---${appId}`;
            return;
        }
        let gameData = await ctx.service.game.findOneGame(appId);
        if (gameData) {
            let { role } = ctx.helper;
            if (gameData.role < role.normalGame) {
                ctx.body = `暂无权限，请联系管理员---appId---${appId}`;
            } else {
                await next();
            }
        } else {
            ctx.body = "暂无用户";
        }

    };
};